import type { VbenFormProps } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { type VxeGridProps } from '@vben/plugins/vxe-table';

class TableConfigBuilder {
  private config: any;

  build = (): VxeGridProps => {
    return this.config;
  };

  withSearchForm = (formOptions: VbenFormProps) => {
    this.config = Object.assign({}, this.config, { formOptions });
    return this;
  };

  constructor(config: VxeTableGridOptions = {}) {
    this.config = Object.assign(
      {},
      {
        gridOptions: {
          checkboxConfig: {
            highlight: true,
            labelField: 'name',
          },
          height: 'auto',
          keepSource: true,
          toolbarConfig: {
            custom: true,
            export: true,
            refresh: true,
            resizable: true,
            search: true,
            zoom: true,
          },
          ...config,
        },
      },
    );
  }
}

export function withDefaultTableConfig(props: VxeTableGridOptions) {
  return new TableConfigBuilder(props);
}
